<?php

namespace services\models;

/**
 * This is the ActiveQuery class for [[\common\models\Cart]].
 *
 * @see \common\models\Cart
 */
class CartQuery extends \yii\db\ActiveQuery
{
    /*public function active()
    {
        return $this->andWhere('[[status]]=1');
    }*/

    /**
     * @inheritdoc
     * @return \common\models\Cart[]|array
     */
    public function all($db = null)
    {
        return parent::all($db);
    }

    /**
     * @inheritdoc
     * @return \common\models\Cart|array|null
     */
    public function one($db = null)
    {
        return parent::one($db);
    }

    /**
     * 购物车显示
     * @param $bestry_uid
     * @return array|\common\models\Cart[ProductDetail,GoodsDetail]
     */
    public function cartAll($bestry_uid)
    {

        return Cart::find()
            ->innerJoinWith('productDetail')
            ->innerJoinWith('goodsDetail')
            ->where(['bestry_uid' => $bestry_uid])->all();

    }


    /**
     * get cart:number product_spec goods_name ,
     * @param $bestry_uid
     * @param $cart_ids
     * @return array|\common\models\Cart[Product, ProductStock, GoodsDetail]
     */
    public function cartForOrder($bestry_uid, $cart_ids)
    {
        return Cart::find()
            ->innerJoinWith('product')
            ->innerJoinWith('productStock')
            ->innerJoinWith('goodsDetail')
            ->where(['bestry_uid' => $bestry_uid])
            ->andWhere(['in', 'cart_id', $cart_ids])
            ->all();
    }
}
